<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript">
        function WebSocketTest()
        {
            if ("WebSocket" in window)
            {
                alert("您的浏览器支持 WebSocket!");

                // 打开一个 web socket
                var ws = new WebSocket("ws://192.168.1.86:8080/ws");
                document.getElementById("myId").onkeypress=function (event) {

                    if(event.keyCode == 13) {
                        ws.send(document.getElementById("myId").value);
                    }
                };
                ws.onopen = function()
                {
                    // Web Socket 已连接上，使用 send() 方法发送数据
                    ws.send("add");
                    // alert("数据发送中...");
                };

                ws.onmessage = function (evt)
                {
                    var received_msg = evt.data;
                    // alert("数据已接收..." + received_msg);
                    console.log("receive:" + received_msg)
                };

                ws.onclose = function()
                {
                    // 关闭 websocket
                    alert("连接已关闭...");
                };
            }

            else
            {
                // 浏览器不支持 WebSocket
                alert("您的浏览器不支持 WebSocket!");
            }
        }


    </script>
</head>
<body>
    <p>hello world</p>
    <h1>jlllll</h1>
    <div id="sse">
        <a href="javascript:WebSocketTest()">运行 WebSocket</a>
    </div>

    <p>接收到了：</p>

    <span>aa</span>
    <input id="myId" type="text" placeholder="输入文字" value=""/>

</body>
</html>